const express = require("express");
const fs = require("fs");
const router = express.Router();
const path = require("path");

//上传图片模板
const multer = require("multer");

//define stroage for the images
const storage = multer.diskStorage({
  //destination for files
  destination: (req, file, cb) => {
    cb(null, "public");
  },
  //add back the extension
  filename: (req, file, cb) => {
    console.log(file);
    cb(null, Date.now() + path.extname(file.originalname));
  },
});

//upload parameters for multer
const upload = multer({ storage: storage });

router.post("/upload", upload.single("image"), (req, res) => {
  res.send("Image Uploaded");
});
module.exports = router;
